using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using Northwind.Domain.Entities;

namespace Northwind.Web.Controls
{
    public partial class ManyToManyControl : System.Web.UI.UserControl
    {
        protected void employeeDropDownList_OnSelectedIndexChanged(object s, EventArgs e)
        {
            LoadTerritories();
        }

        protected void Page_Load(object s, EventArgs e)
        {
            if( !Page.IsPostBack )
            {
                employeeDropDownList.DataSource = Employee.Broker.GetAll();
                employeeDropDownList.DataBind();
                LoadTerritories();
            }
        }

        private void LoadTerritories()
        {
            int employeeID = int.Parse(employeeDropDownList.SelectedValue);
            Employee employee = Employee.Broker.GetByID(employeeID);
            grid.DataSource = employee.TerritoryList;
            grid.DataBind();
        }
    }
}